home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / battlane.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  9KB  |  422 lines

  1. /***************************************************************************
  2.  
  3.     Battlelane
  4.  
  5.     TODO: Properly support flip screen
  6.           Tidy / Optimize and add dirty layer support
  7.  
  8. ***************************************************************************/
  9.  
  10. #include "driver.h"
  11. #include "vidhrdw/generic.h"
  12.  
  13. static struct osd_bitmap *screen_bitmap;
  14.  
  15. size_t battlane_bitmap_size;
  16. unsigned char *battlane_bitmap;
  17. static int battlane_video_ctrl;
  18.  
  19. const int battlane_spriteram_size=0x100;
  20. static unsigned char battlane_spriteram[0x100];
  21.  
  22. const int battlane_tileram_size=0x800;
  23. static unsigned char battlane_tileram[0x800];
  24.  
  25.  
  26. static int flipscreen;
  27. static int battlane_scrolly;
  28. static int battlane_scrollx;
  29.  
  30. extern int battlane_cpu_control;
  31.  
  32. static struct osd_bitmap *bkgnd_bitmap;  /* scroll bitmap */
  33.  
  34.  
  35. WRITE_HANDLER( battlane_video_ctrl_w )
  36. {
  37.     /*
  38.     Video control register
  39.  
  40.         0x80    = ????
  41.         0x0e    = Bitmap plane (bank?) select  (0-7)
  42.         0x01    = Scroll MSB
  43.     */
  44.  
  45.     battlane_video_ctrl=data;
  46. }
  47.  
  48. READ_HANDLER( battlane_video_ctrl_r )
  49. {
  50.     return battlane_video_ctrl;
  51. }
  52.  
  53. void battlane_set_video_flip(int flip)
  54. {
  55.  
  56.     if (flip != flipscreen)
  57.     {
  58.         // Invalidate any cached data
  59.     }
  60.  
  61.     flipscreen=flip;
  62.  
  63.     /*
  64.     Don't flip the screen. The render function doesn't support
  65.     it properly yet.
  66.     */
  67.     flipscreen=0;
  68.  
  69. }
  70.  
  71. WRITE_HANDLER( battlane_scrollx_w )
  72. {
  73.     battlane_scrollx=data;
  74. }
  75.  
  76. WRITE_HANDLER( battlane_scrolly_w )
  77. {
  78.     battlane_scrolly=data;
  79. }
  80.  
  81. WRITE_HANDLER( battlane_tileram_w )
  82. {
  83.     battlane_tileram[offset]=data;
  84. }
  85.  
  86. READ_HANDLER( battlane_tileram_r )
  87. {
  88.     return battlane_tileram[offset];
  89. }
  90.  
  91. WRITE_HANDLER( battlane_spriteram_w )
  92. {
  93.     battlane_spriteram[offset]=data;
  94. }
  95.  
  96. READ_HANDLER( battlane_spriteram_r )
  97. {
  98.     return battlane_spriteram[offset];
  99. }
  100.  
  101.  
  102. WRITE_HANDLER( battlane_bitmap_w )
  103. {
  104.     int i, orval;
  105.  
  106.     orval=(~battlane_video_ctrl>>1)&0x07;
  107.  
  108.     if (orval==0)
  109.         orval=7;
  110.  
  111.     for (i=0; i<8; i++)
  112.     {
  113.         if (data & 1<<i)
  114.         {
  115.             screen_bitmap->line[(offset / 0x100) * 8+i][(0x2000-offset) % 0x100]|=orval;
  116.         }
  117.         else
  118.         {
  119.             screen_bitmap->line[(offset / 0x100) * 8+i][(0x2000-offset) % 0x100]&=~orval;
  120.         }
  121.     }
  122.     battlane_bitmap[offset]=data;
  123. }
  124.  
  125. READ_HANDLER( battlane_bitmap_r )
  126. {
  127.     return battlane_bitmap[offset];
  128. }
  129.  
  130.  
  131.  
  132.  
  133. #ifdef MAME_DEBUG
  134. void battlane_dump_bitmap(void)
  135. {
  136.     int i;
  137.     FILE *fp=fopen("SCREEN.DMP", "w+b");
  138.     if (fp)
  139.     {
  140.         for ( i=0; i<0x20*8-1; i++)
  141.         {
  142.             fwrite(screen_bitmap->line[i], 0x20*8, 1, fp);
  143.         }
  144.         fclose(fp);
  145.     }
  146.     fp=fopen("SPRITES.DMP", "w+b");
  147.     if (fp)
  148.     {
  149.         fwrite(battlane_spriteram, 0x100, 1, fp);
  150.         fclose(fp);
  151.     }
  152.  
  153.     fp=fopen("TILES.DMP", "w+b");
  154.     if (fp)
  155.     {
  156.         fwrite(battlane_tileram, 0x800, 1, fp);
  157.         fclose(fp);
  158.     }
  159.  
  160.  
  161. }
  162. #endif
  163.  
  164.  
  165.  
  166.  
  167. /***************************************************************************
  168.  
  169.   Start the video hardware emulation.
  170.  
  171. ***************************************************************************/
  172. int battlane_vh_start(void)
  173. {
  174.     screen_bitmap = osd_create_bitmap(0x20*8, 0x20*8);
  175.     if (!screen_bitmap)
  176.     {
  177.         return 1;
  178.     }
  179.  
  180.     battlane_bitmap=malloc(battlane_bitmap_size);
  181.     if (!battlane_bitmap)
  182.     {
  183.         return 1;
  184.     }
  185.  
  186.     memset(battlane_spriteram, 0, battlane_spriteram_size);
  187.     memset(battlane_tileram,255, battlane_tileram_size);
  188.  
  189.     bkgnd_bitmap = osd_create_bitmap(0x0200, 0x0200);
  190.     if (!bkgnd_bitmap)
  191.     {
  192.         return 1;
  193.     }
  194.  
  195.  
  196.     return 0;
  197. }
  198.  
  199.  
  200.  
  201. /***************************************************************************
  202.  
  203.   Stop the video hardware emulation.
  204.  
  205. ***************************************************************************/
  206. void battlane_vh_stop(void)
  207. {
  208.     if (screen_bitmap)
  209.     {
  210.         osd_free_bitmap(screen_bitmap);
  211.     }
  212.     if (battlane_bitmap)
  213.     {
  214.         free(battlane_bitmap);
  215.     }
  216.     if (bkgnd_bitmap)
  217.     {
  218.         free(bkgnd_bitmap);
  219.     }
  220. }
  221.  
  222. /***************************************************************************
  223.  
  224.   Build palette from palette RAM
  225.  
  226. ***************************************************************************/
  227.  
  228. INLINE void battlane_build_palette(void)
  229. {
  230.     int offset;
  231.     unsigned char *PALETTE =
  232.         memory_region(REGION_PROMS);
  233.  
  234.     for (offset = 0; offset < 0x40; offset++)
  235.     {
  236.           int palette = PALETTE[offset];
  237.           int red, green, blue;
  238.  
  239.           blue   = ((palette>>6)&0x03) * 16*4;
  240.           green  = ((palette>>3)&0x07) * 16*2;
  241.           red    = ((palette>>0)&0x07) * 16*2;
  242.  
  243.           palette_change_color (offset, red, green, blue);
  244.     }
  245. }
  246.  
  247. /*
  248.  
  249. void battlane_vh_convert_color_prom (unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  250. {
  251.  
  252. }
  253. */
  254.  
  255. /***************************************************************************
  256.  
  257.   Draw the game screen in the given osd_bitmap.
  258.   Do NOT call osd_update_display() from this function, it will be called by
  259.   the main emulation engine.
  260.  
  261. ***************************************************************************/
  262. void battlane_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  263. {
  264.     int scrollx,scrolly;
  265.     int x,y, offs;
  266.  
  267.     /* Scroll registers */
  268.     scrolly=256*(battlane_video_ctrl&0x01)+battlane_scrolly;
  269.     scrollx=256*(battlane_cpu_control&0x01)+battlane_scrollx;
  270.  
  271.  
  272.     battlane_build_palette();
  273.     if (palette_recalc ())
  274.     {
  275.          // Mark cached layer as dirty
  276.     }
  277.  
  278.     /* Draw tile map. TODO: Cache it */
  279.     for (offs=0; offs <0x400;  offs++)
  280.     {
  281.         int sx,sy;
  282.         int code=battlane_tileram[offs];
  283.         int attr=battlane_tileram[0x400+offs];
  284.  
  285.         sx=(offs&0x0f)+(offs&0x100)/16;
  286.         sy=((offs&0x200)/2+(offs&0x0f0))/16;
  287.         drawgfx(bkgnd_bitmap,Machine->gfx[1+(attr&0x01)],
  288.                code,
  289.                (attr>>1)&0x07,
  290.                !flipscreen,flipscreen,
  291.                sx*16,sy*16,
  292.                NULL,
  293.                TRANSPARENCY_NONE, 0);
  294.  
  295.     }
  296.     /* copy the background graphics */
  297.     {
  298.         int scrlx, scrly;
  299.         scrlx=-scrollx;
  300.         scrly=-scrolly;
  301.         copyscrollbitmap(bitmap,bkgnd_bitmap,1,&scrly,1,&scrlx,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  302.     }
  303.     {
  304.     char baf[256];
  305.     char baf2[40];
  306.     baf[0]=0;
  307.  
  308.     /* Draw sprites */
  309.     for (offs=0; offs<0x0100; offs+=4)
  310.     {
  311.            /*
  312.            0x80=bank 2
  313.            0x40=
  314.            0x20=bank 1
  315.            0x10=y double
  316.            0x08=Unknown - all vehicles have this bit clear
  317.            0x04=x flip
  318.            0x02=y flip
  319.            0x01=Sprite enable
  320.            */
  321.           int attr=battlane_spriteram[offs+1];
  322.           int code=battlane_spriteram[offs+3];
  323.           code += 256*((attr>>6) & 0x02);
  324.           code += 256*((attr>>5) & 0x01);
  325.           if (offs > 0x00a0)
  326.           {
  327.                sprintf(baf2, "%02x ", attr);
  328.                strcat(baf,baf2);
  329.           }
  330.  
  331.           if (attr & 0x01)
  332.           {
  333.                int sx=battlane_spriteram[offs+2];
  334.                int sy=battlane_spriteram[offs];
  335.                int flipx=attr&0x04;
  336.                int flipy=attr&0x02;
  337.                if (!flipscreen)
  338.                {
  339.                     sx=240-sx;
  340.                     sy=240-sy;
  341.                     flipy=!flipy;
  342.                     flipx=!flipx;
  343.                }
  344.                if ( attr & 0x10)  /* Double Y direction */
  345.                {
  346.                    int dy=16;
  347.                    if (flipy)
  348.                    {
  349.                         dy=-16;
  350.                    }
  351.                    drawgfx(bitmap,Machine->gfx[0],
  352.                      code,
  353.                      0,
  354.                      flipx,flipy,
  355.                      sx, sy,
  356.                      &Machine->drv->visible_area,
  357.                      TRANSPARENCY_PEN, 0);
  358.  
  359.                     drawgfx(bitmap,Machine->gfx[0],
  360.                      code+1,
  361.                      0,
  362.                      flipx,flipy,
  363.                      sx, sy-dy,
  364.                      &Machine->drv->visible_area,
  365.                      TRANSPARENCY_PEN, 0);
  366.                 }
  367.                 else
  368.                 {
  369.                    drawgfx(bitmap,Machine->gfx[0],
  370.                      code,
  371.                      0,
  372.                      flipx,flipy,
  373.                      sx, sy,
  374.                      &Machine->drv->visible_area,
  375.                      TRANSPARENCY_PEN, 0);
  376.                 }
  377.           }
  378.     }
  379.  
  380.  
  381. //    usrintf_showmessage(baf);
  382.     }
  383.     /* Draw foreground bitmap */
  384.     if (flipscreen)
  385.     {
  386.         for (y=0; y<0x20*8; y++)
  387.         {
  388.             for (x=0; x<0x20*8; x++)
  389.             {
  390.                 int data=screen_bitmap->line[y][x];
  391.                 if (data)
  392.                 {
  393.                     bitmap->line[255-y][255-x]=Machine->pens[data];
  394.                 }
  395.             }
  396.         }
  397.     }
  398.     else
  399.     {
  400.         for (y=0; y<0x20*8; y++)
  401.         {
  402.             for (x=0; x<0x20*8; x++)
  403.             {
  404.                 int data=screen_bitmap->line[y][x];
  405.                 if (data)
  406.                 {
  407.                     bitmap->line[y][x]=Machine->pens[data];
  408.                 }
  409.             }
  410.         }
  411.  
  412.     }
  413.  
  414. #ifdef MAME_DEBUG
  415.     if (keyboard_pressed(KEYCODE_S))
  416.     {
  417.          battlane_dump_bitmap();
  418.     }
  419. #endif
  420.  
  421. }
  422.